Skip to content

Fix memory leaks in fuzzer modules detected by cppchecker #18081#18082

Closed
Lung-Alexandra wants to merge 1 commit intophp:PHP-8.3from
Lung-Alexandra:fix/memory-leak
Closed

Fix memory leaks in fuzzer modules detected by cppchecker #18081#18082
Lung-Alexandra wants to merge 1 commit intophp:PHP-8.3from
Lung-Alexandra:fix/memory-leak

Conversation

@Lung-Alexandra
Copy link
Copy Markdown
Contributor

This PR fixes #18081.

This pull request addresses several memory leak issues detected by cppchecker in the following files:

  • fuzzer-json.c (line 39):
    Added a free(data) call to release the allocated memory before returning.

  • fuzzer-mbregex.c (line 39):
    Implemented a similar fix by freeing the allocated memory for data when fuzzer_request_startup() fails.

  • fuzzer-unserialize.c (line 38):
    Now frees orig_data before returning when an error is detected.

  • fuzzer-unserializehash.c (line 43):
    Modified the error path to call free(orig_data) if fuzzer_request_startup() fails.

These changes ensure that memory allocated is properly released if fuzzer_request_startup() fails, preventing memory leaks.

@ndossche
Copy link
Copy Markdown
Member

This affects lower branches too, please target the lowest supported bugfix branch, i.e. PHP-8.3.

@ndossche
Copy link
Copy Markdown
Member

It's probably also better to just move the allocation under the request initialization, then you don't even need the call to free.

@Lung-Alexandra Lung-Alexandra changed the base branch from master to PHP-8.3 March 16, 2025 07:12
@TimWolla
Copy link
Copy Markdown
Member

This needs to be properly rebased when changing the target branch.

@Lung-Alexandra
Copy link
Copy Markdown
Contributor Author

@TimWolla squashed and rebased over PHP-8.3

Copy link
Copy Markdown
Contributor

@staabm staabm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tabs vs spaces mixed up in all files

Copy link
Copy Markdown
Member

@ndossche ndossche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix indentation to use tabs

Copy link
Copy Markdown
Member

@ndossche ndossche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

ndossche added a commit that referenced this pull request Mar 16, 2025
* PHP-8.3:
  Fix GH-18082: Memory leaks in fuzzer SAPI error paths
@ndossche ndossche closed this in 38e553e Mar 16, 2025
ndossche added a commit that referenced this pull request Mar 16, 2025
* PHP-8.4:
  Fix GH-18082: Memory leaks in fuzzer SAPI error paths
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

4 participants